package com.Lgwd.utils;


import com.Lgwd.enums.ExceptionsEnumCode;
import lombok.Data;

/**
 * 接口请求返回体
 * 
 * @author ZJY
 *
 * @param <T>
 */
@Data
public class ResponseData<T> {

	private T data;

	private String message;

	private String code;

	private int errCode;

	private String msg;

	public ResponseData() {
	}

	public ResponseData(String code, String message, T data) {
		this.code = code;
		this.message = message;
		this.data = data;
	}

	public ResponseData(String code, String message) {
		this.code = code;
		this.message = message;
	}

	public ResponseData(ExceptionsEnumCode enums, T data) {
		this.code = enums.getName();
		this.message = enums.getValue();
		this.data = data;
	}

	/**
	 * 根据枚举类型返回指定ResponseData
	 * 
	 * @param enums
	 * @param data
	 * @return
	 */
	public static <T> ResponseData<T> buildResponseData(ExceptionsEnumCode enums, T data) {
		return new ResponseData<>(enums.getName(), enums.getValue(), data);
	}

	/**
	 * data 可以为空
	 * 
	 * @param data
	 * @return
	 */
	public static <T> ResponseData<T> defaultSuccess(T data) {
		return buildResponseData(ExceptionsEnumCode.SUCCESS, data);
	}

	/**
	 * data 可以为空
	 * 
	 * @param data
	 * @return
	 */
	public static <T> ResponseData<T> defaultFail(T data) {
		return buildResponseData(ExceptionsEnumCode.FAIL, data);
	}
	
	/**
	 * data 可以为空
	 * 
	 * @param data
	 * @return
	 */
	public static <T> ResponseData<T> defaultSuccess() {
		return buildResponseData(ExceptionsEnumCode.SUCCESS, null);
	}

	/**
	 * data 可以为空
	 * 
	 * @param data
	 * @return
	 */
	public static <T> ResponseData<T> defaultFail() {
		return buildResponseData(ExceptionsEnumCode.FAIL, null);
	}
	
	public static ResponseData ok(Object data){
		return buildResponseData(ExceptionsEnumCode.SUCCESS,data);
	}
	public static ResponseData ok(String message){
		return buildResponseData(ExceptionsEnumCode.SUCCESS,message);
	}
}
